﻿using System.ComponentModel;

namespace SharePointUtilitiesForDevelopers.Client
{
    /// <summary>
    /// Defines the type of tree nodes
    /// </summary>
    public enum TreeNodeType
    {
        Site,
        SiteContentTypes,
        SiteContentType,
        SiteLists,
        List,
        ListViews,
        ListView,
        ListFields,
        ListField,
        ListCustomFields,
        ListAllFields,
        ListContentTypes,
        ListContentType,
        ListContentTypeFields,
        ListContentTypeField
    }

    /// <summary>
    /// A class that contains information about a tree node;
    /// </summary>
    public class TreeNodeInfo
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TreeNodeInfo"/> class.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="nodeType">The node type.</param>
        /// <param name="tag">The tag.</param>
        public TreeNodeInfo(string title, TreeNodeType nodeType, object tag)
        {
            Title = title;
            NodeType = nodeType;
            Tag = tag ?? this;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TreeNodeInfo"/> class.
        /// </summary>
        /// <param name="title">The title.</param>
        /// <param name="description">The description</param>
        /// <param name="nodeType">The node type.</param>
        /// <param name="tag">The tag.</param>
        public TreeNodeInfo(string title, string description, TreeNodeType nodeType, object tag)
            : this(title, nodeType, tag)
        {
            Description = description;
        }

        /// <summary>
        /// Gets or sets a value indicating whether [children loaded].
        /// </summary>
        /// <value><c>true</c> if [children loaded]; otherwise, <c>false</c>.</value>
        [ReadOnly(true)]
        [Browsable(false)]
        public bool ChildrenLoaded { get; set; }

        /// <summary>
        /// Gets or sets the type of the node.
        /// </summary>
        /// <value>The type of the node.</value>
        [ReadOnly(true)]
        [Browsable(false)]
        public TreeNodeType NodeType { get; set; }

        /// <summary>
        /// Gets or sets the tag.
        /// </summary>
        /// <value>The tag.</value>
        [ReadOnly(true)]
        [Browsable(false)]
        public object Tag { get; set; }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        [ReadOnly(true)]
        [Description("The node title.")]
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        [ReadOnly(true)]
        [Description("The node description.")]
        public string Description { get; set; }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return Title;
        }
    }
}
